from Common.basepage import BasePage
from PageLocators.MainPage_locator import MainPageLocator as loc
import re
from Common.handle_log import do_log
from Common.connect_to_device import d_one, d_two_device

import time


class MainPage(BasePage):

    def go_to_login(self):
        self.click_element(loc.user_loc, "点击头像")
        time.sleep(2)
        self.click_element(loc.login_loc, "点击立即登录")
        time.sleep(2)
        self.click_element(loc.agree_loc, "点击同意")
        time.sleep(2)
        img_path = self.save_img("保存登录二维码")
        return img_path

    def get_new_code(self):
        self.save_img("保存登录二维码")

    def scan_code(self):
        self.click_element(loc.scan_loc, "点击扫码")
        time.sleep(2)
        self.click_element(loc.album_loc, "点击图库")
        time.sleep(2)
        self.click_element(loc.module_loc, "点击...")
        time.sleep(2)
        self.click_element(loc.more_loc, "点击浏览")
        time.sleep(2)
        self.click_element(loc.files_loc, "点击文件管理")
        time.sleep(2)
        self.click_element(loc.sdcard_loc, "点击内部储存设备")
        time.sleep(2)
        self.click_element(loc.aaa_loc, "点击目录")
        time.sleep(2)
        self.click_element(loc.pic_loc, "点击图片")
        time.sleep(2)
        self.click_element(loc.ok_loc, "点击确认")
        time.sleep(3)
        self.click_element(loc.comfirm_loc, "点击授权登录")


if __name__ == '__main__':
    img_path = MainPage(device="d_one").go_to_login()
    # MainPage(device="d_one").get_new_code()
    d_two_device.sync.push(img_path, "/sdcard/DCIM/Camera/iqiyilogin.jpg")
    MainPage(device="d_two").scan_code()
